<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="x-csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="/css/app.css">
</head>
<body>



<table width="400" border="0" align="center">
    <tr>
        <th>选项</th>
        <th>发件人</th>
        <th>邮箱</th>
        <th>电话</th>
    </tr>
    <tbody id="tbs">
    @foreach($info[0] as $v)
        <tr class="{{$v->id}}">
            <input type="hidden" value="{{$v->id}}">
            {{--<span>{{$v->id}}</span>--}}
            <td><input type="checkbox" name="check[]"></td>
            <td>{{$v->username}}</td>
            <td>{{$v->email}}</td>
            <td>{{$v->mobile}}</td>
        </tr>
    @endforeach
    <tr>
        <td><a href="1">首页</a></td>
        <td><a href="{{action('ModelCT@page_before',['id'=>$info[1]])}}">上一页</a></td>
        <td><a href="{{action('ModelCT@page_next',['id'=>$info[1]])}}">下一页</a></td>
    </tr>
    <tr>
        <th>选项</th>
        <td colspan="3" align="center">
            <input type="button" id="qx" onclick="changebox('qx')" value="全选">
            <input type="button" id="qxx" onclick="changebox('qxx')" value="取消全选">
            <input type="button" id="fx" onclick="changebox('fx')" value="反选">
            <input type="button" id="del" onclick="del()" value="删除选中附件">
        </td>
    </tr>
    </tbody>
</table>





<script src="https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js"></script>
<script>
    $(function () {
        $('#tab').on('click','.row',function () {
            var user_info = [];
            var list = $(this).children()
            for (a=0;a<list.length;a++){
                user_info.push(list[a].innerHTML);
            }
            console.log(user_info)
        })
    })
</script>
<script type="text/javascript" language="javascript">
    function changecolor(){
        var tr=document.getElementsByTagName("tr");
        tr[0].style.background="#0066ff";
        tr[tr.length-1].style.background="#0066ff";
    }
    function changebox(type) {
        var tbs = document.getElementById("tbs");
        var chks = tbs.getElementsByTagName("input");
        switch (type) {
            case "qx":
                for (var i = 0; i < chks.length; i++) {
                    chks[i].checked = true;
                }
                break;
            case "qxx":
                for (var i = 0; i < chks.length; i++) {
                    chks[i].checked = false;
                }
                break;
            case "fx":
                for (var i = 0; i < chks.length; i++) {
                    if (chks[i].checked == true) {
                        chks[i].checked = false;
                    } else {
                        chks[i].checked = true;
                    }
                }
                break;
        }
    }
    function del(){
        var input=document.getElementsByName("check[]");
        var del_li =[];
        for(var i=input.length-1; i>=0; i--){
            if(input[i].checked==true){
                var td=input[i].parentNode;
                var tr=td.parentNode;
                var table=tr.parentNode;
                var dd = tr.firstElementChild.value
                del_li.push(dd)
            }
        }


        if (confirm('really')){
            $.post("{{ url('/del') }}", {
                "_token": "{{ csrf_token() }}",
                "keys": del_li
            }, function (e) {
                if (e.code) {
                    alert(e.info)
                    location.reload()
                    // console.log(e.info)
                } else {
                    alert(e.info)
                    // console.log(e.info)
                }
            })
        }else {
            return false;
        }

        // console.log(del_li)
    }
</script>
</body>
</html>